<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: create by allen.qiang
// +----------------------------------------------------------------------

/**
 * 基础选项管理ajax类
 * @package  ajax
 * @subpackage  backend
 * @author   create by allen.qiang
 */

quanli_require('module/base/system/sysItemMultilevel.class.php');

class ajax_itemMultilevel {

    public function execute() {

        if (isset($_REQUEST['operFlg']) && is_numeric($_REQUEST['operFlg']) && $_REQUEST['operFlg'] > 0) {

            switch ($_REQUEST['operFlg']) {

                case 1://显示第一级
                    $this->getTheFirstLevel();
                    break;

                case 2://显示第二级
                    $this->getTheSecondLevel();
                    break;

                case 3://显示第三级
                    $this->getThethirdLevel();
                    break;

                case 4://显示第四级
                    $this->getTheFourLevel();
                    break;

                default:
                    $this->toReturn('参数错误');
                    break;

            }

        } else {
            $this->toReturn('参数错误');
        }


    }

    /**
     * 返回信息
     * @param string $message
     * @param int $code
     * @param mixed $data
     */
    private function toReturn( $message, $code = 400, $data = '' ) {

        die( json_encode( array( 'code' => $code, 'message' => $message, 'data' => $data ) ) );

    }

    /**
     * 获取第一级数据
     */
    public  function getTheFirstLevel(){

        global $G_SHOP;

        //实例化基础设置（多级）类
        $sysItemMultilevel = new sysItemMultilevel($G_SHOP->DBCA);

        $arg_array['parent_id'] = 0;

        $arg_array['sortname'] = 'sort_order';

        $arg_array['sortorder'] = 'ASC';

        //获取第一级数据
        $first_level_array = $sysItemMultilevel->getItemMultilevelList($arg_array);

        returnJsonData('ok',200,$first_level_array);

    }

    /**
     * 根据第一级id获取第二级信息
     */
    public  function getTheSecondLevel(){

        global $G_SHOP;

        //实例化基础设置（多级）类
        $sysItemMultilevel = new sysItemMultilevel($G_SHOP->DBCA);

        $arg_array['parent_id'] = $_REQUEST['first_id'];

        $arg_array['sortname'] = 'sort_order';

        $arg_array['sortorder'] = 'ASC';

        //获取第二级数据
        $second_level_array = $sysItemMultilevel->getItemMultilevelList($arg_array);

        returnJsonData('ok',200,$second_level_array);

    }

    /**
     * 根据第二级id获取第三级信息
     */
    public  function getTheThirdLevel(){

        global $G_SHOP;

        //实例化基础设置（多级）类
        $sysItemMultilevel = new sysItemMultilevel($G_SHOP->DBCA);

        //定义返回的数组
        $third_level_array = array();

        if($_REQUEST['second_id'] != ''){

            $arg_array['parent_id'] = $_REQUEST['second_id'];

            $arg_array['sortname'] = 'sort_order';

            $arg_array['sortorder'] = 'ASC';

            //获取第三级数据
            $third_level_array = $sysItemMultilevel->getItemMultilevelList($arg_array);

            returnJsonData('ok',200,$third_level_array);
        }else{

            returnJsonData('ok',200,$third_level_array);
        }

    }

    /**
     * 根据第三级id获取第四级信息
     */
    public  function getTheFourLevel(){

        global $G_SHOP;

        //实例化基础设置（多级）类
        $sysItemMultilevel = new sysItemMultilevel($G_SHOP->DBCA);

        //定义返回的数组
        $four_level_array = array();

        if($_REQUEST['third_id'] != ""){

            $arg_array['parent_id'] = $_REQUEST['third_id'];

            $arg_array['sortname'] = 'sort_order';

            $arg_array['sortorder'] = 'ASC';

            //获取第四级数据
            $four_level_array = $sysItemMultilevel->getItemMultilevelList($arg_array);

            returnJsonData('ok',200,$four_level_array);

        }else{

            returnJsonData('ok',200,$four_level_array);
        }


    }

}
